package com.swz.dcrm.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.swz.dcrm.R;
import com.swz.dcrm.base.ViewHolder;
import com.swz.dcrm.model.WorkRemind;
import com.swz.dcrm.util.DateUtils;
import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersAdapter;

import java.util.Date;
import java.util.List;

public class WorkRemindAdapter extends CustomAdapter<WorkRemind> implements StickyRecyclerHeadersAdapter<AddressBookAdapter.HeaderViewHolder> {
    public WorkRemindAdapter(Context context,  List<WorkRemind> datas) {
        super(context, R.layout.item_work_remind, datas);
    }

    @Override
    protected void convert(ViewHolder holder, WorkRemind workRemind, int position) {
             if(workRemind.getCount()==0){
                 holder.setText(R.id.tv_title,mContext.getString(R.string.work_remind_sign1,workRemind.getName()));
             }else {
                 holder.setText(R.id.tv_title,mContext.getString(R.string.work_remind_sign,workRemind.getCount(),workRemind.getName()));
             }

             holder.setText(R.id.tv_date,DateUtils.dateFormat(mDatas.get(position).getTime(),"HH:mm"));
             holder.itemView.setClickable(false);
        if(DateUtils.dateFormat(workRemind.getTime(),"yyyy-MM-dd").equals(DateUtils.getCurrentDate())){
            holder.getView(R.id.tv_detail).setVisibility(View.VISIBLE);
        }else {
            holder.getView(R.id.tv_detail).setVisibility(View.GONE);
        }
             holder.setOnClickListener(R.id.tv_detail, v -> {
                onClickListener.onItemClick(workRemind);
             });

    }

    @Override
    public long getHeaderId(int position) {
        Date date= DateUtils.dateParse(mDatas.get(position).getTime(),"yyyy-MM-dd");

        return date.getTime();
    }

    @Override
    public AddressBookAdapter.HeaderViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_letter,parent,false);
        return new AddressBookAdapter.HeaderViewHolder(view);
    }

    @Override
    public void onBindHeaderViewHolder(AddressBookAdapter.HeaderViewHolder headerViewHolder, int i) {
            if(DateUtils.dateFormat(mDatas.get(i).getTime(),"yyyy-MM-dd").equals(DateUtils.getCurrentDate())){
                headerViewHolder.letter.setText("今天");
            }else {
                headerViewHolder.letter.setText("昨天");
            }
    }
}
